//编辑
function modifyRole(_this) {
   var lock = false;
   var id = $(_this).attr("data-id");
   var url = ctx + "/admin/role/modify";
   var layTitle = "编辑角色";
   getRole(id);
   layer.open({
       title: layTitle,
       content: $("#modifyModel"),
       type: 1,
       closeBtn: 2,
       skin: 'layui-layer-molv',
       area: ['600px', '440px'], //宽高
       btn: ['确定', '取消'],
       yes: function (index, layero) {
           var selfFill = attch();
           if (!lock) {
               lock = true;
               axios.post(url, selfFill)
                   .then(function (data) {
                       if (!data.data.success) {
                           layer.msg(data.data.info, {icon: 2});
                           lock = false;
                           return;
                       }
                       layer.msg(data.data.info, {icon: 6});
                       layer.close(index);
                       myTable.draw(false);
                   })
                   .catch(function (data) {
                       layer.msg('网络异常', {icon: 5});
                   });

           }
       }
   });
}



//===========================================获取单个通知信息==================================================
//获取公告通知
function getRole(id) {
    var url = ctx + "/admin/role/get";
    var oneObj = null;
    axios.get(url,
        {params: {id: id}})
        .then(function (res) {
            if (!res.data.success) {
                layer.msg(res.data.info, {icon: 2});
                return;
            }
            oneObj = res.data.data;
            fillObj(oneObj);
        })
        .catch(function (res) {
            layer.msg('网络异常', {icon: 5});
        })
}

//============================================弹窗页面信息=====================================================
//获取页面信息
function attch() {
    var oneObj = {};
    oneObj['name'] = $("#modifyModel").find("input[name='name']").val();
    oneObj['description'] = $("#description").find("input[name='description']").val();
    oneObj['remark'] = $("#modifyModel").find("textarea[name='remark']").val();
    oneObj['weight'] = $("#weightId").find("option:selected").val();
    oneObj['id'] = $("#modifyModel").find("input[name='id']").val();
    return oneObj;
}

//填充页面信息
function fillObj(obj) {
    $("#modifyModel").find("input[name='name']").val(obj.name);
    $("#modifyModel").find("input[name='description']").val(obj.description);
    $("#modifyModel").find("textarea[name='remark']").val(obj.remark);
    $("#weightId").find("option[value=" + obj.weight + "]").prop("selected", true);
    $("#modifyModel").find("input[name='id']").val(obj.id);

}

//清空页面信息
function clearObj() {
    $("#modifyModel").find("textarea[name='remark']").val("");
    $("#modifyModel").find("input[name='name']").val("");
    $("#modifyModel").find("input[name='id']").val("");
    $("#modifyModel").find("textarea[name='remark']").val();
    $("#weightId").val("");
}
